package com.kevin.controller.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kevin.common.api.PageDTO;
import com.kevin.common.api.R;
import com.kevin.service.entity.SysMessage;
import com.kevin.service.entity.SysMessage;
import com.kevin.service.query.SysParamsQuery;
import com.kevin.service.service.SysMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 消息推送
 *
 * @author wh
 * @date 2023/12/8 16:16
 */
@RestController
@RequestMapping("sys/message")
@Api(tags = "消息推送")
@AllArgsConstructor
public class SysMessageController {
    private final SysMessageService messageService;

    @GetMapping("page")
    @ApiOperation(value = "分页")
//    @SaCheckPermission(value = "sys:params:all")
    public R<PageInfo<SysMessage>> page(PageDTO pageDTO, SysParamsQuery query) {
        PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
        return R.ok(new PageInfo<>(messageService.list()));
    }

    @GetMapping("{id}")
    @ApiOperation(value = "信息")
//    @SaCheckPermission(value = "sys:params:all")
    public R<SysMessage> get(@PathVariable("id") Long id) {
        return R.ok(messageService.getById(id));
    }

    @PostMapping
    @ApiOperation(value = "保存")
//    @SaCheckPermission(value = "sys:params:all")
    public R<String> save(@RequestBody SysMessage vo) {
        messageService.saveP(vo);
        return R.ok();
    }

//    @PutMapping
//    @ApiOperation(value = "修改")
////    @SaCheckPermission(value = "sys:params:all")
//    public R<String> update(@RequestBody @Valid SysMessage vo) {
//        messageService.update(vo);
//        return R.ok();
//    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @SaCheckPermission(value = "sys:params:all")
    public R<String> delete(@RequestBody List<Long> idList) {
        messageService.removeBatchByIds(idList);
        return R.ok();
    }
}
